using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Microsoft.VisualStudio.Modeling;

namespace DslCrossModelFramework.UI {
    public partial class ModelElementList : Form {
        public ModelElementList(CrossModelManager manager) {
            InitializeComponent();
            BindToModelDirectory(manager);
            OKButton.Enabled = false;
        }

        private void BindToModelDirectory(CrossModelManager manager) {
            manager.GetModelDirectory().PreloadAllModelFiles();
            foreach (ModelElement modelElement in manager.GetModelDirectory().AllElements()) {
                modelElementListBox.Items.Add(manager.GetModelElementName(modelElement));

            }
        }

        private void OKButton_Click(object sender, EventArgs e) {
            modelElementReference = modelElementListBox.SelectedItem as string;
            DialogResult = System.Windows.Forms.DialogResult.OK;
            
            Close();
        }

        private string modelElementReference = string.Empty;
        public string ModelElementReference {
            get { return modelElementReference;  }
        }

        private void modelElementListBox_SelectedIndexChanged(object sender, EventArgs e) {
            OKButton.Enabled = modelElementListBox.SelectedIndex > -1;
        }
    }
}